package Java实验.实验六;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class Task {

    public void runThread(int num) {
        //请在此添加实现代码

       /********** Begin **********/
      // 在这里开启线程 获取线程执行的结果
        try {
            ThreadCallable tc = new ThreadCallable(num);
            FutureTask<Integer> ft = new FutureTask<>(tc);
            new Thread(ft).start();
            System.out.println("线程的返回值为：" + ft.get());
        } catch (Exception e) {
            e.printStackTrace();
        }

        /********** End **********/
    }
}

        //请在此添加实现代码

        /********** Begin **********/

        /* 在这里实现Callable接口及方法 */
class ThreadCallable implements Callable<Integer> {
    int num;

    public ThreadCallable() {
        super();
    }

    public ThreadCallable(int num) {
        super();
        this.num = num;
    }

    public Integer call() throws Exception {
        return fun(num);
    }

    public int fun(int num) {
        if (num < 3) {
            return 1;
        } else
            return fun(num - 1) + fun(num - 2);
    }

}


        /********** End **********/
